package com.lljin.study.userserviceprovider.controller;

import com.lljin.study.client.OrderServiceFeignClient;
import com.lljin.study.dto.OrderDto;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lljin
 * @description hystrix test
 * @date 2020/7/19 23:50
 */
@DefaultProperties(defaultFallback = "defaultFallback")
@RestController
public class HystrixFeignController {

    private final OrderServiceFeignClient orderServiceFeignClient;

    public HystrixFeignController(OrderServiceFeignClient orderServiceFeignClient) {
        this.orderServiceFeignClient = orderServiceFeignClient;
    }

    @GetMapping("/hystrix/feign/{id}")
    public String hystrixTest(@PathVariable String id) {
        return orderServiceFeignClient.order(id);
    }

    @PostMapping("/hystrix/feign/order")
    public String timeout() {
        OrderDto orderDto = new OrderDto();
        orderDto.setOrderId(123);
        return orderServiceFeignClient.insert(orderDto);
    }

    private String fallback(int num) {
        return "触发服务降级";
    }

    private String defaultFallback() {
        return "默认降级方法";
    }
}
